/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


function AjaxObj()
{
    var xmlhttp = null;

    if (window.XMLHttpRequest)
    {
        xmlhttp = new XMLHttpRequest();

        if (xmlhttp.overrideMimeType)
        {
            xmlhttp.overrideMimeType('text/xml');
        }
    }
    else if (window.ActiveXObject)
    {
        // Internet Explorer    
        try
        {
            xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e)
        {
            try
            {
                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e)
            {
                xmlhttp = null;
            }
        }

        if (!xmlhttp && typeof XMLHttpRequest != 'undefined')
        {
            xmlhttp = new XMLHttpRequest();

            if (!xmlhttp)
            {
                failed = true;
            }
        }
    }
    return xmlhttp;
}

function cargarTabla(nombre, caracteristics, tipo, actividad) {
    if (validar(txtNombre) == 1 && selTipo(tipo) == 1) {
        var url = "brain.php";
        var ajax = new AjaxObj();
        ajax.open("POST", url, false);
        ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        ajax.send("nombre=" + nombre + "&caracteristica=" + caracteristics + "&tipo=" + tipo + "&actividad=" + 1);
        document.getElementById("contenedor").innerHTML = ajax.responseText;
        limpiar();
    }

}

function limpiar() {
    txtNombre.value = "";
    txtaCaracteristicas.value = "";
    txtFechini.value = "";
    txtFechfin.value = "";
    txtTotal.value = "";
    document.getElementById("slActi").innerHTML = "";
}
function validar(objeto) {
    if (objeto.value == "") {
        document.getElementById("contenedor").innerHTML = "<span style='color: red;'>No ha ingresado un nombre!</span> ";
        return 0;
    } else {
        return 1;
    }
}

function selTipo(valor) {
    if (valor == "int") {
        if (slActi.value == "") {
            var url = "brain.php";
            var ajax = new AjaxObj();
            ajax.open("POST", url, false);
            ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            ajax.send("nombre=" + "0" + "&caracteristica=" + "0" + "&tipo=" + "0" + "&actividad=" + 0);
            document.getElementById("slActi").innerHTML = ajax.responseText;
            return 0;
        } else {
            return 1;
        }

    } else {
        return 1;
    }
}
function detener(id) {
    var url = "brain.php";
    var ajax = new AjaxObj();
    ajax.open("POST", url, false);
    ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    ajax.send("nombre=" + id + "&caracteristica=" + 0 + "&tipo=" + 0 + "&actividad=" + 2);
    document.getElementById("contenedor").innerHTML = ajax.responseText;
}
function iniciar() {
    var url = "brain.php";
    var ajax = new AjaxObj();
    ajax.open("POST", url, false);
    ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    ajax.send("nombre=" + '' + "&caracteristica=" + '' + "&tipo=" + '' + "&actividad=" + '10');
    var divTag = document.createElement("div");
    divTag.id = "contenedor";
    divTag.setAttribute("align", "center");
    divTag.style.margin = "0px auto";
    divTag.className = "dynamicDiv";
    divTag.innerHTML = ajax.responseText;
    document.body.appendChild(divTag);


}